//
//  LogoScene.m
//  SpaceStorm
//
//  Created by 祥 雍 on 13-6-3.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//
//
//  进游戏的Logo界面，同时后台加载必要的配置文件和精灵图集

#import "LogoScene.h"
#import "LoginScene.h"
#import "Variable.h"

#import "ShipModelInfoMgr.h"
#import "AirplaneInfoMgr.h"
#import "BattleGroupInfoMgr.h"
#import "BulletModelInfoMgr.h"
#import "ChapterInfoMgr.h"
#import "EquipInfoMgr.h"
#import "EquipModelInfoMgr.h"
#import "EventRewardInfoMgr.h"
#import "MonsterInfoMgr.h"
#import "ShipInfoMgr.h"
#import "StorageScene.h"
#import "LevelUpInfoMgr.h"
#import "BattleDestroyWin.h"
#import "SimpleAudioEngine.h"


@implementation LogoScene

+(CCScene *) scene
{
	// 'scene' is an autorelease object.
	CCScene *scene = [CCScene node];
	
	// 'layer' is an autorelease object.
	LogoScene *layer = [LogoScene node];   //先注释

    
//    MyTest *layer = [MyTest node];
    
//    StorageScene *layer = [StorageScene node];
    
//    BattleDestroyWin* layer = [BattleDestroyWin node];
    
//    BattleDestroyDetails* layer = [BattleDestroyDetails node];
    
//    StorageScene * layer = [StorageScene node];
    

	// add layer as a child to scene
	[scene addChild: layer];
    
	// return the scene
	return scene;
}

-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if( (self=[super init])) 
    {
        CGSize size = [[CCDirector sharedDirector] winSize];
        
        //零临时的
        CCSprite* bg = [CCSprite spriteWithFile:@"jaggedlogo.jpg"]; 
        bg.scaleX = size.width / bg.contentSize.width;
        bg.scaleY = size.height / bg.contentSize.height;
		bg.position = ccp(size.width/2,size.height/2); 
		[self addChild:bg];

        
        CCLabelTTF* label = [CCLabelTTF labelWithString:@"我是可爱的LOGO,偷偷加载配置和精灵图集" fontName:@"AppleGothic" fontSize:16];
        label.color = ccc3(255, 0, 0);
        label.position = CGPointMake(size.width /2, size.height /2 + 150);
        label.anchorPoint = CGPointMake(0.5, 0.5);
        [self addChild:label];
        
        //预定更新，下一帧执行，执行一次
        [self schedule:@selector(showTofficeGameAnimation:)]; 
    }
	return self;
}

/**
	显示公司的Logo动画
	@param sender 
 */
- (void) showTofficeGameAnimation:(id)sender
{
    //停止选择器
	[self unschedule:@selector(showTofficeGameAnimation:)];
    

    
       
    
 
    CCSprite *baseNormal = [CCSprite spriteWithFile:@"Icon-Small.png"];//Icon-Small
    
	CCSprite *baseClick = [CCSprite spriteWithFile:@"Icon-Small.png"];//Icon-72
    
    CCSprite *fleeNormal = [CCSprite spriteWithFile:@"Icon-Small.png"];//中文显示不出来
	CCSprite *fleeClick = [CCSprite spriteWithFile:@"Icon-Small.png"];
    // game menu
	CCMenuItemSprite* base;     //基地
    CCMenuItemSprite* flee;     //舰队
    
    base = [CCMenuItemSprite itemFromNormalSprite:baseNormal selectedSprite:baseClick target:self selector:@selector(onmennuItemHandler:)];
    base.position = CGPointMake(0, 100);//ccp(baseNormal.contentSize.width / 2,200 - baseNormal.contentSize.height / 2 - 72);
    
    flee = [CCMenuItemSprite itemFromNormalSprite:fleeNormal selectedSprite:fleeClick target:self selector:@selector(onmennuItemHandler:)];
    flee.position = CGPointMake(0, 20);
    CCMenu* menu;
    menu = [CCMenu menuWithItems:base, flee, nil];
    menu.position = ccp(200, 100);//CGPointMake(200, 100);
    [self addChild:menu];
    
 //   CCSprite *baseButtonName= [CCSprite spriteWithSpriteFrameName:@"base.png"];

    
   // baseButtonName.position = ccp(baseButtonName.contentSize.width / 2 + 77, 150);
   // [self addChild:baseButtonName];
    

    
    
    
    
    
    
    
    


    //初始化游戏
    [self gameInit];
    
    //预定更新，下一帧执行，执行一次
  //  [self schedule:@selector(showLogo:)];
}

-(void) onmennuItemHandler:(id)sender
{
    CCLOG(@"按钮单击");
    //初始化游戏
       [self gameInit];
    
    //预定更新，下一帧执行，执行一次
     [self schedule:@selector(showLogo:)];
}    




/**
	游戏初始化
 */
-(void) gameInit
{
    extern BOOL showXMLLog;
    showXMLLog = NO;
    
    //加载配置文件
    [[ShipModelInfoMgr sharedManager] initConfig:@"shipModel.xml"];             //舰船模型表
    [[AirplaneInfoMgr sharedManager] initConfig:@"airplane.xml"];               //舰载机表
    [[BattleGroupInfoMgr sharedManager] initConfig:@"battleGroup.xml"];         //战斗组表
    [[BulletModelInfoMgr sharedManager] initConfig:@"bulletModel.xml"];         //弹药模型表
    [[ChapterInfoMgr sharedManager] initConfig:@"chapter.xml"];                 //章节格子关联表
    [[EquipInfoMgr sharedManager] initConfig:@"equip.xml"];                     //装备表
    [[EquipModelInfoMgr sharedManager] initConfig:@"equipModel.xml"];           //装备模型表
    [[EventRewardInfoMgr sharedManager] initConfig:@"eventReward.xml"];         //事件奖励
    [[MonsterInfoMgr sharedManager] initConfig:@"monster.xml"];                 //战役敌军装配标准（怪物表）
    [[ShipInfoMgr sharedManager] initConfig:@"ship.xml"];                       //舰船表
    [[LevelUpInfoMgr sharedManager] initConfig:@"levelup.xml"];                 //等级表
    
    //加载游戏音乐
    //缓冲音乐
    [[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"menu.mp3"];
    [[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"battle.mp3"];  
      
    //缓冲音效
//    [[SimpleAudioEngine sharedEngine] preloadEffect:@"autogun.mp3"]; 
    
    
    //加载精灵图集
    //TODO
}

/**
	显示游戏的Logo动画
	@param sender 
 */
-(void) showLogo:(id)sender
{
    //取消选择器
	[self unschedule:@selector(showLogo:)]; 
	
    //播放游戏Logo动画
    //TODO
    
    //预定选择器，切换存档选择场景
	[self schedule:@selector(showLoginScene:)]; 
}


/**
 进入游戏创建，进度选择场景，下一帧执行。
 @param sender
 */
- (void) showLoginScene:(id)sender
{
    //停止选择器
	[self unschedule:@selector(showLoginScene:)]; 
    
	//场景切换
	CCTransitionFade* trans = [CCTransitionFade transitionWithDuration:1.0 scene:[StorageScene scene]];
	[[CCDirector sharedDirector] replaceScene: trans];
}

// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
	// in case you have something to dealloc, do it in this method
	// in this particular example nothing needs to be released.
	// cocos2d will automatically release all the children (Label)
	
	// don't forget to call "super dealloc"
	[super dealloc];
}

@end
